package org.jcodetools.io;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Created by 熊彦 on 2017-06-16.
 *
 * @email javadevyan@163.com
 */
public class PropertiesUtils {
    /**
     * 从classpath目录中加载properties配置文件，并将内容加载到properties对象中并返回
     *
     * @param fileName 文件名
     * @return 返回Properties对象
     */
    public static Properties load(String fileName) {
        Properties properties = new Properties();
        InputStream in = null;
        try {
            in = PropertiesUtils.class.getClassLoader().getResourceAsStream(fileName);
            properties.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return properties;
    }
}
